<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Sign extends Controller {

	private $user;
	
    public function before()
    {
        parent::before();
    }

    public function after()
    {        
        parent::after();
    }
    
    public function action_index()
	{
		$this->user = lib_user::instance();
		//var_dump($this->user);exit;
		if (($this->user->username === 'admin') && ($this->user->power === 1) && ($this->user->parentId === 0)){
			lib_admin::redirect();
		}elseif (($this->user->username != 'guest') && ($this->user->power != 0)){
			lib_url::redirect();
		}
		
		//lib_user::$instance->register('admin','shaoya.cook');
		if ($post = lib_security::killinject($this->request->post())){
			if (isset($post['username']) && strlen($post['username'])){
				if (isset($post['password']) && strlen($post['password'])){
					if (lib_user::$instance->login($post['username'],$post['password'])){
						lib_url::redirect('sign');
					}else{
						echo '<script>alert("'.lib_message::get().'");</script>';
					}
				}else{
					echo '<script>alert("请输入密码");</script>';
				}
			}else{
				echo '<script>alert("请输入用户名");</script>';
			}
		}
		
		echo lib_view::factory('default')->set('post',$post);
	}
	
	public function action_logout()
	{
		$this->user = lib_user::instance();
		lib_user::$instance->logout();
		lib_url::redirect(project::config()->host);
	}
} // End Welcome
